package com.ag.zlw.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.ag.bean.TbExpertArea;
import com.ag.common.BaseAction;
import com.ag.zlw.service.ExpertAreaService;
import com.ag.common.IDUtil;

/**
 * 专家领域
 * 
 * @author 钟龙伟
 * 
 */

@Scope("prototype")
@Controller("ExpertAreaAction")
public class ExpertAreaAction extends BaseAction {
	private static final long serialVersionUID = -1478025497648926124L;
	@Resource(name = "ExpertAreaService")
	private ExpertAreaService service;
	private List<TbExpertArea> ExpertAreaList;
	private String message;
	private String expareaId;
	private String expareaName;

	TbExpertArea tbExpertArea = new TbExpertArea();

	public String find() {
		try {
			ExpertAreaList = service.findAll();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "main";
	}

	public String delete() {
		tbExpertArea.setExpareaId(expareaId);
		try {
			service.delete(tbExpertArea);
			this.setMessage("delete success!");
		} catch (Exception e) {
			this.setMessage("delete fail!");
		}
		return "delete_success";
	}

	public String add() {
		tbExpertArea.setExpareaName(expareaName);
		tbExpertArea.setA(IDUtil.PRESERVE);
		try {
			service.save(tbExpertArea);
			this.setMessage("save success!");
		} catch (Exception e) {
			this.setMessage("save fail!");
		}
		return "add_success";
	}

	public String modify() {
		tbExpertArea.setExpareaId(expareaId);
		tbExpertArea.setExpareaName(expareaName);
		tbExpertArea.setA(IDUtil.PRESERVE);
		try {
			service.modify(tbExpertArea);
			this.setMessage("modify success!");
		} catch (Exception e) {
			this.setMessage("modify fail!");
		}
		return "modify_success";
	}

	public List<TbExpertArea> getExpertAreaList() {
		return ExpertAreaList;
	}

	public void setExpertAreaList(List<TbExpertArea> expertAreaList) {
		ExpertAreaList = expertAreaList;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String getExpareaId() {
		return expareaId;
	}

	public void setExpareaId(String expareaId) {
		this.expareaId = expareaId;
	}

	public String getExpareaName() {
		return expareaName;
	}

	public void setExpareaName(String expareaName) {
		this.expareaName = expareaName;
	}

}
